package com.hiyee.api.config;

import com.hiyee.api.interceptor.TokenVerifyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 接口服务配置类
 *
 * @author WangBin
 */
@Configuration
public class ApiConfiguration implements WebMvcConfigurer {

    @Autowired
    private CurrentCustomerArgumentResolver currentCustomerArgumentResolver;

    @Bean
    public HandlerInterceptor tokenVerifyInterceptor() {
        return new TokenVerifyInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // jwt token拦截器
        registry.addInterceptor(tokenVerifyInterceptor()).addPathPatterns("/**").order(1);
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(currentCustomerArgumentResolver);
    }
}
